package com.ybkj.o2o.sales.service.impl;

import com.ybkj.o2o.sales.entity.Application;
import com.ybkj.o2o.sales.mapper.ApplicationMapper;
import com.ybkj.o2o.sales.service.ApplicationService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by shine on 15/8/21.
 */
@Service
public class DefaultApplicationService implements ApplicationService {

  @Autowired
  private ApplicationMapper applicationMapper;


  @Override
  public boolean exists(String name) {

    Long total = applicationMapper.exists(name);

    return total > 0;
  }

  @Override
  public List<Application> findAll(int offset, int rows) {

    List<Application> list = applicationMapper.findAll(offset, rows);
    return list;
  }

  @Override
  public long count() {
    long count = applicationMapper.count();
    return count;
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void insert(Application application) {
    applicationMapper.insert(application);
  }

  @Override
  public Application fetch(Long id) {
    Application app = applicationMapper.fetch(id);
    return app;
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void update(Application application) {
    applicationMapper.update(application);

  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void delete(Long id) {
    applicationMapper.delete(id);
  }

  @Override
  public Application fetchByAppId(String appId) {
    Application app = applicationMapper.fetchByAppId(appId);
    return app;
  }
}
